#!/usr/bin/env python

import threading
import json

import WebSocketManage

class ThreadManage(threading.Thread):
    def __init__(self, connection1, connection2):
        threading.Thread.__init__(self)
        self.con1 = connection1
        self.con2 = connection2
    
    def run(self):
        self.__listenOneConnection(self.con1)
        print "connection1 done"
        self.__listenOneConnection(self.con2)

    def __listenOneConnection(self, connection):
        while True:
            try:
                recv_message = WebSocketManage.recv_data(connection, 10000)
                if (recv_message):
                    print recv_message
                else:
                    print "close socket"
                    break
            except:
                self.con.close()
                break

